function queryStr(options) {
    const arr = []

    for (let key in options) {
        arr.push(key + '=' + options[key])
    }
    return arr.join('&')
}

function ajax(options) {
    let xhr = new XMLHttpRequest()

    if (options.type === 'get') {
        xhr.open('get', options.url + '?' + queryStr(options.data), true)
    }
    if (options.type === 'post') {
        xhr.open('post', options.url, true)
    }
    if (options.type === 'get') {
        xhr.send()
    }
    if (options.type === 'post') {
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
        xhr.send(queryStr(options.data))
    }

    xhr.onload = function () {
        if (options.success) {
            options.success(xhr.responseText)
        }
    }
}
